package com.thon.entity.topic;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.thon.commons.persistence.IdEntity;
import com.thon.entity.system.User;
import org.hibernate.annotations.*;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

/**
 * Created by Chen on 2016/2/9.
 * 出题表
 */
@Entity
@Table(name = "to_topic")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Topic extends IdEntity {

    private String name;   //题目名称
    private Integer type;   //类型：0技术类/1商务类
    private Integer source;    //来源：0科研横向课题/1科研纵向课题/2教师自拟题目/3学生自拟题目
    private Integer restriction;    //人数限制
    private Integer studentNumber = 0;    //当前人数
    private String description;    //题目描述
    private Date createDate;    //出题时间
    private Integer pass = 0;   //是否通过审核：0等待教师审核/1教师审查通过/2未通过教师审核/3教务审查通过/4未通过教务审核
    private Integer creatorType;    //出题人类型：0老师/1学生

    private User directTeacher;  //指导老师（只针对学生自主命题）
    private User creator;      //出题人

    public Topic(){
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getSource() {
        return source;
    }

    public void setSource(Integer source) {
        this.source = source;
    }

    public Integer getRestriction() {
        return restriction;
    }

    public void setRestriction(Integer restriction) {
        this.restriction = restriction;
    }

    public Integer getStudentNumber() {
        return studentNumber;
    }

    public void setStudentNumber(Integer studentNumber) {
        this.studentNumber = studentNumber;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "creator_id")
    @NotFound(action = NotFoundAction.IGNORE)
    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    public Integer getPass() {
        return pass;
    }

    public void setPass(Integer pass) {
        this.pass = pass;
    }

    public Integer getCreatorType() {
        return creatorType;
    }

    public void setCreatorType(Integer creatorType) {
        this.creatorType = creatorType;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "direct_teacher_id")
    @NotFound(action = NotFoundAction.IGNORE)
    public User getDirectTeacher() {
        return directTeacher;
    }

    public void setDirectTeacher(User directTeacher) {
        this.directTeacher = directTeacher;
    }
}
